package com.alibaba.serverless.service.handle;

import com.alibaba.serverless.common.filter.FilterChain;
import com.alibaba.serverless.common.filter.FilterChainFactory;
import com.alibaba.serverless.domain.ReceiveParams;
import com.alibaba.serverless.service.filter.EmailOneMinNotRepeatFilter;
import com.alibaba.serverless.service.filter.EmailSendTooMuchFilter;
import com.alibaba.serverless.service.handle.v20201108.config.SmtpSendType;
import com.aliyuncs.dm.model.v20151123.BatchSendMailRequest;
import com.aliyuncs.dm.model.v20151123.SingleSendMailRequest;

/**
 * @author mac_zyj
 */
public class SmtpContent {
    /**
     * 责任链配置
     */
    private final FilterChain<ReceiveParams> filterChain= FilterChainFactory.buildFilterChain(
            EmailOneMinNotRepeatFilter.class,
            EmailSendTooMuchFilter.class
    );
    /**当前策略*/
    private final BaseSmtpStrategy currentStrategy;

    public SmtpContent(int type) {
        currentStrategy= SmtpSendType.getSmtpStrategyByType(type);
    }

    /**
     * 生成简单邮件请求
     * @param smtpParams 邮件参数
     * @return 简单邮件对象
     */
    public SingleSendMailRequest sendSingleMailRequest(ReceiveParams smtpParams){
        filterChain.doFilter(smtpParams);
        return currentStrategy.sendSingleMailRequest(smtpParams);
    }

    /**
     * 生成模板邮件请求
     * @return 模板邮件请求
     */
    public BatchSendMailRequest sendBatchMailRequest() {
        return currentStrategy.sendBatchMailRequest();
    }

}
